package asteroids.model.programs.parsing.expressions;

import java.util.Map;

import asteroids.Util;
import asteroids.model.Ship;
import asteroids.model.programs.parsing.types.*;

/**
 * A class of smaller than expressions.
 * A smaller than expression returns true if and only if the left-hand operand is smaller than the right-hand operand.
 * 
 * @author Thijs Dieltjens - Wim Konings
 * @version 2.0
 */
public class SmallerThan extends LogicalExpr{

	public SmallerThan(Expression e1, Expression e2, int line, int column) {
		super(e1, e2, line, column);
	}

	@Override
	public BooleanLiteral eval(Ship ship, Map<String, Type> globals){
		Type t1=getLeftOperand().eval(ship, null);
		Type t2=getRightOperand().eval(ship, null);

		if(t1 instanceof DoubleLiteral && t2 instanceof DoubleLiteral){
			boolean result=  Util.fuzzyLessThan(((DoubleLiteral) t1).getValue(),((DoubleLiteral) t2).getValue());
			return new BooleanLiteral(result);
		}
		return new BooleanLiteral();
	}
}


